﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="r_comercial_funil_de_vendas.aspx.cs" Inherits="relatorios_r_comercial_funil_de_vendas" %>
<%
    /*string Permissao_RelatoriosFinanceirosComercial = "" + this.Session["Permissao_RelatoriosFinanceirosComercial"];
    if (Permissao_RelatoriosFinanceirosComercial != "1")
    {
        this.Response.Redirect("../login.aspx");
    }*/
%>
<div style="background-color: White; min-height: 500px;">
    <%
        double allTotal = 0;        
        DateTime now = DateTime.Now;
        string month = this.Request["month"];
        string year = this.Request["year"];            
        int iMonth = -1;
        int iYear = -1;            
        int maxDay = 31;
        
        // Month
        if (string.IsNullOrEmpty(month) == true)
        {
            iMonth = now.Month;
        }
        else
        {
            try
            {
                iMonth = int.Parse(month);
            }
            catch { iMonth = now.Month; }
        }
        // Year            
        if (string.IsNullOrEmpty(year) == true)
        {
            iYear = now.Year;
        }
        else
        {
            try
            {
                iYear = int.Parse(year);
            }
            catch { iYear = now.Year; }                
        }        
        maxDay = DateTime.DaysInMonth(iYear, iMonth);            
        //DateTime targetDate = DateTime.Now;     

        DateTime targetDate = new DateTime(iYear, iMonth, 1);
        DateTime maxDate = new DateTime(iYear, iMonth, maxDay);                        
    %>
    <center>
        <form>
            <table>
                <tr>
                    <td>Mês</td>
                    <td>Ano</td>
                    <td>Colab.</td>
                    <td></td>
                </tr>

                <tr>
                    <td>
                        <input type="text" id="month" name="month" value="<%= iMonth %>" />
                    </td>
                    <td>
                        <input type="text" id="year" name="year" value="<%= iYear %>" />
                    </td>
                    <td>
                        <select name="worker">
                            <option value="">Todos</option>
                            <% this.WriteWorkers(this.Request["worker"], targetDate, maxDate); %>
                        </select>                        
                    </td>
                    <td><input type="submit" value="ok" /></td>
                </tr>
            </table>
        </form>
    </center>

    <style>
        .myTable td
        {
            border: 1px solid;
        }
    </style>
    <center>
        <table class="myTable">
            <tr>
                <td>BC</td>
                <td>Contato Inicial</td>
                <td>Prospect</td>
                <td>Prospect Qualificado</td>
                <td>Em negociação</td>
                <td>Fechado</td>
            </tr>         
            
            <%
                List<PL.Models.SellFunnelData> allData = this.LoadFunnelData(targetDate, maxDate, this.Request["worker"]);
                foreach (var data in allData)
                {
            %>
                    <tr>
                        <td><%= data.Worker%></td>
                        <td><%= data.InitialContact%></td>
                        <td><%= data.Prospect%></td>
                        <td><%= data.QualifiedProspect%></td>
                        <td><%= data.Negotiating%></td>
                        <td><%= data.WeHaveADeal%></td>
                    </tr>
            <%
                }
            %>  
             
            <tr>
                <td>
                    <center>
                        <strong>--</strong>
                    </center>
                </td>
                <td>
                    <center>
                        <strong>--</strong>
                    </center>
                </td>
                <td>
                    <center>
                        <strong>--</strong>
                    </center>
                </td>
                <td>
                    <center>
                        <strong>--</strong>
                    </center>
                </td>
                <td>
                    <center>
                        <strong>--</strong>
                    </center>
                </td>
                <td>
                    <center>
                        <strong>--</strong>
                    </center>
                </td>
            </tr>

            <tr>
                <td>
                    <center>
                        <strong>Total</strong>
                    </center>
                </td>
                <td>
                    <strong>100%</strong> - <%= this.Total.InitialContact %>
                </td>
                <td>
                    <strong><%= (100 * double.Parse(this.Total.Prospect) / (double.Parse(this.Total.InitialContact))).ToString("0.##") %>%</strong> - <%= this.Total.Prospect %>
                </td>
                <td>
                    <strong><%= (100 * double.Parse(this.Total.QualifiedProspect) / (double.Parse(this.Total.InitialContact))).ToString("0.##")%>%</strong> - <%= this.Total.QualifiedProspect %>
                </td>
                <td>
                    <strong><%= (100 * double.Parse(this.Total.Negotiating) / (double.Parse(this.Total.InitialContact))).ToString("0.##")%>%</strong> - <%= this.Total.Negotiating %>
                </td>
                <td>
                    <strong><%= (100 * double.Parse(this.Total.WeHaveADeal) / (double.Parse(this.Total.InitialContact))).ToString("0.##")%>%</strong> - <%= this.Total.WeHaveADeal %>
                </td>
            </tr>

            <tr>
                <td>
                    <center>
                        <strong>Referência</strong>
                    </center>
                </td>
                <td>
                    <strong>100%</strong>
                </td>
                <td>
                    <strong>72%</strong>
                </td>
                <td>
                    <strong>65%</strong>
                </td>
                <td>
                    <strong>28%</strong>
                </td>
                <td>
                    <strong>10%</strong>
                </td>
            </tr>

        </table>
    </center>
    <%        
    %>
</div>